package com.ruoyi.blogs.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.SysUserMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.blogs.mapper.BsCommentLikeRecordMapper;
import com.ruoyi.blogs.mapper.BsCommentMapper;
import com.ruoyi.blogs.domain.BsComment;
import com.ruoyi.blogs.domain.BsCommentLikeRecord;
import com.ruoyi.blogs.service.IBsCommentLikeRecordService;

/**
 * 评论点赞点踩记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-11-05
 */
@Service
public class BsCommentLikeRecordServiceImpl implements IBsCommentLikeRecordService 
{
    @Autowired
    private BsCommentLikeRecordMapper bsCommentLikeRecordMapper;

    @Autowired
    private SysUserMapper userMapper;

    @Autowired
    private BsCommentMapper bsCommentMapper;

    /**
     * 查询评论点赞点踩记录
     * 
     * @param id 评论点赞点踩记录主键
     * @return 评论点赞点踩记录
     */
    @Override
    public BsCommentLikeRecord selectBsCommentLikeRecordById(String id)
    {
        return bsCommentLikeRecordMapper.selectBsCommentLikeRecordById(id);
    }

    /**
     * 查询评论点赞点踩记录列表
     * 
     * @param bsCommentLikeRecord 评论点赞点踩记录
     * @return 评论点赞点踩记录
     */
    @Override
    public List<BsCommentLikeRecord> selectBsCommentLikeRecordList(BsCommentLikeRecord bsCommentLikeRecord)
    {
        return bsCommentLikeRecordMapper.selectBsCommentLikeRecordList(bsCommentLikeRecord);
    }

    /**
     * 新增评论点赞点踩记录
     * 
     * @param bsCommentLikeRecord 评论点赞点踩记录
     * @return 结果
     */
    @Override
    public int insertBsCommentLikeRecord(BsCommentLikeRecord bsCommentLikeRecord)
    {
        if(bsCommentLikeRecord.getOpType() == 1){
            SysUser user = new SysUser();
            // 查询点赞评论的用户
            BsComment bsComment = bsCommentMapper.selectBsCommentById(bsCommentLikeRecord.getCommentId());
            user.setUserId(bsComment.getUserId());
            user.setLikeNum(0);
            userMapper.updateUserNum(user);
        }
        bsCommentLikeRecord.setCreateTime(DateUtils.getNowDate());
        bsCommentLikeRecord.setUpdateTime(DateUtils.getNowDate());
        bsCommentLikeRecord.setUserId(SecurityUtils.getUserId());
        return bsCommentLikeRecordMapper.insertBsCommentLikeRecord(bsCommentLikeRecord);
    }

    /**
     * 修改评论点赞点踩记录
     * 
     * @param bsCommentLikeRecord 评论点赞点踩记录
     * @return 结果
     */
    @Override
    public int updateBsCommentLikeRecord(BsCommentLikeRecord bsCommentLikeRecord)
    {
        bsCommentLikeRecord.setUpdateTime(DateUtils.getNowDate());
        return bsCommentLikeRecordMapper.updateBsCommentLikeRecord(bsCommentLikeRecord);
    }

    /**
     * 批量删除评论点赞点踩记录
     * 
     * @param ids 需要删除的评论点赞点踩记录主键
     * @return 结果
     */
    @Override
    public int deleteBsCommentLikeRecordByIds(String[] ids)
    {
        return bsCommentLikeRecordMapper.deleteBsCommentLikeRecordByIds(ids);
    }

    /**
     * 删除评论点赞点踩记录信息
     * 
     * @param id 评论点赞点踩记录主键
     * @return 结果
     */
    @Override
    public int deleteBsCommentLikeRecordById(String id)
    {
        return bsCommentLikeRecordMapper.deleteBsCommentLikeRecordById(id);
    }

    @Override
    public int deleteBsLikeRecordByQuery(BsCommentLikeRecord bsCommentLikeRecord) {
        return bsCommentLikeRecordMapper.deleteBsLikeRecordByQuery(bsCommentLikeRecord);
    }
}
